//
//  PayPasswordView.m
//  PigMarket
//
//  Created by mac on 2019/5/4.
//  Copyright © 2019 felix.pigmarket.oc. All rights reserved.
//

#import "PayPasswordView.h"

@implementation PayPasswordView

#pragma mark - init method
- (instancetype)init
{
    self = [super init];
    if (self) {
        [self initView];
        [self initLayout];
    }
    return self;
}

- (void)initView {
    // 添加子控件
    [self addSubview:self.passwordView];
    [self addSubview:self.titleLab];
    [self addSubview:self.tips];
    [self addSubview:self.confirmBtn];
    [self addSubview:self.forgetPasswordBtn];
}

- (void)initLayout {
    // 布局子控件
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(30);
        make.top.mas_equalTo(36);
        make.height.mas_equalTo(30);
    }];
    [self.tips mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(30);
        make.top.mas_equalTo(self.passwordView.mas_bottom).offset(10);
        make.height.mas_equalTo(18);
        make.right.mas_equalTo(-37);
    }];
    [self.confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.mas_centerX);
        make.height.mas_equalTo(48);
        make.top.mas_equalTo(self.tips.mas_bottom).offset(40);
        make.left.mas_equalTo(30);
        make.right.mas_equalTo(-30);
    }];
    [self.forgetPasswordBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.confirmBtn.mas_right);
        make.top.mas_equalTo(self.confirmBtn.mas_bottom).offset(20);
        make.size.mas_equalTo(CGSizeMake(80, 20));
    }];
}

#pragma mark - getter and setter
- (UILabel *)titleLab {
    if (!_titleLab) {
        _titleLab = [[UILabel alloc] init];
        _titleLab.textColor = [UIColor textBlackColor];
        _titleLab.font = [UIFont systemFontOfSize:22];
    }
    return _titleLab;
}
- (PZXVerificationCodeView *)passwordView {
    if (!_passwordView) {
        CGFloat x = 30;
        CGFloat y = 100;//CGRectGetMaxY(self.titleLab.size) + 25;
        _passwordView = [[PZXVerificationCodeView alloc] initWithFrame:CGRectMake(x, y, (SCREEN_WIDTH - 60), (SCREEN_WIDTH - 60)/6)];
        _passwordView.selectedColor = [UIColor blackColor];
        //        _passwordView.center = self.view.center;
        _passwordView.VerificationCodeNum = 6;
        _passwordView.isSecure = YES;
        _passwordView.Spacing = 0;
    }
    return _passwordView;
}
- (UILabel *)tips {
    if (!_tips) {
        _tips = [[UILabel alloc] init];
        _tips.textColor = [UIColor tipsGrayColor];
        _tips.font = [UIFont systemFontOfSize:13];
        _tips.text = @"请设置6位数字密码";
    }
    return _tips;
}
- (UIButton *)confirmBtn {
    if (!_confirmBtn) {
        _confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_confirmBtn setBackgroundImage:[UIImage imageNamed:@"btn_nomal_bg"] forState:UIControlStateNormal];
    }
    return _confirmBtn;
}


- (UIButton *)forgetPasswordBtn {
    if (!_forgetPasswordBtn) {
        _forgetPasswordBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_forgetPasswordBtn setTitle:@"忘记密码?" forState:UIControlStateNormal];
        [_forgetPasswordBtn setTitleColor:[UIColor colorWithHexString:@"#7A7A7A"] forState:UIControlStateNormal];
        _forgetPasswordBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        _forgetPasswordBtn.isNeedAnimation = YES;
        
        @weakify(self);
        _forgetPasswordBtn.tapBlock = ^{
            @strongify(self);
            if (self.dealForgetPasswordBlock) {
                self.dealForgetPasswordBlock();
            }
        };
    }
    return _forgetPasswordBtn;
}

@end
